﻿using System;
using System.Collections.Generic;

namespace CompileApp.Models;

public class Utils
{
    public static Token GetToken(string text)
    {
        string number = "", type = "", value = "";
        text = text.Replace(" ", "");
        text = text.Substring(1, text.Length - 2);

        var list = text.Split("\t", StringSplitOptions.RemoveEmptyEntries);
        if (list.Length >= 3)
        {
            number = list[0];
            type = list[1];
            value = list[2];
        }

        return new Token(Convert.ToInt32(number), type, value);
    }

    public static string GetTokenType(Token token)
    {
        string result = token.Type;

        if (token.Type.Equals("标识符"))
        {
            result = "标识符";
        }
        else if (token.Type.Equals("关键字"))
        {
            result = token.Value;
        }
        else if (token.Type.Equals("界符"))
        {
            result = token.Value;
        }
        else if (token.Type.Equals("操作符"))
        {
            if (token.Value.Length == 1)
            {
                
                if (token.Value.Equals("="))
                {
                    result = "=";
                }
                else
                {
                    result = "单目求值符";
                }
                // result = token.Value;
                
            }
        }
        else if (token.Value.Equals("#"))
        {
            result = "#";
        }

        return result;
    }

    private static HashSet<string> _jfu = new HashSet<string>()
    {
        ",", "(", ")", "{", "}", ";", "#"
    };

    private static HashSet<string> _zlx = new HashSet<string>()
    {
        "int", "float", "double", "char", "string", "bool", "void"
    };
}